#include "header.h"
#include "sig.h"
#include "extern.h"

void sig_handler (int signo)
{
	switch (signo)
	{
		case SIGHUP:
			ServRestartFlag = 1;
			break;
		case SIGINT:
			ServCloseFlag = 1;
			break;
	}
}

int sig_init (void)
{
 int gard;
	/*
		On signal HUP: restart server
		On signal INT: shutdown server
		On signal PIPE: Ignore
	*/
	act.sa_handler = sig_handler;
	sigemptyset (&act.sa_mask);
	act.sa_flags = 0;

	gard = sigaction (SIGHUP, &act, 0);	
		if (gard == -1) return gard;
	gard = sigaction (SIGINT, &act, 0);
		if (gard == -1) return gard;

	actbp.sa_handler = SIG_IGN;
	sigemptyset (&actbp.sa_mask);
	actbp.sa_flags = 0;

	sigaction (SIGPIPE, &actbp, 0);
		if (gard == -1) return gard;

 return 0;
}

